import loginPack from '@/assets/PublicInterface/StoreInterfaces/CurrentAccount/loginPack'
import teacherInfo from '@/assets/PublicInterface/StoreInterfaces/CurrentAccount/teacherInfo'
import studentInfo from '@/assets/PublicInterface/StoreInterfaces/CurrentAccount/studentInfo'
import emptyStudentInfo from '@/assets/PublicStaticValue/views/studentPage/emptyStudentInfo'
const state = {
  Login: false,
  currentAccount: 'null',
  currentInfo: emptyStudentInfo,
  isTeacher: false
}
const getters = {
  getFullState: (state: any): any => {
    return state;
  },
  getCurrentAccount: (state: any): string => {
    return state.currentAccount
  },
  getAccountState: (state: any): object => {
    return {
      Login: state.Login,
      isTeacher: state.isTeacher
    }
  },
  getCurrentInfo: (state: any) => {
    return state.isTeacher ? state.currentInfo as teacherInfo : state.currentInfo as studentInfo
  }
}
const mutations = {
  SetFullState: (state: any, pack: any) => {
    state.Login = pack.Login
    state.currentAccount = pack.currentAccount
    state.currentInfo = pack.currentInfo
    state.isTeacher = pack.isTeacher
  },
  SetCurrentAccount: (state: any, pack: loginPack) => {
    state.currentAccount = pack.currentAccount
    state.currentInfo = pack.infoPack
    state.isTeacher = pack.isTeacher
    state.Login = true
  },
  SetInfo: (state: any, Info: any) => {
    state.currentInfo = {
      ...Info
    }
  },
  Logout: (state: any) => {
    state.Login = false
    state.currentAccount = 'null'
    state.currentInfo = emptyStudentInfo
    state.isTeacher = false
  }
}
const actions = {
  setFullState: ({ commit }: any, pack: any) => {
    commit('SetFullState', pack)
  },
  setCurrentAccount: ({ commit }: any, pack: loginPack) => {
    commit('SetCurrentAccount', pack)
  },
  setInfo: ({ commit }: any, Info: any) => {
    commit('SetInfo', Info)
  },
  logout: ({ commit }: any) => {
    commit('Logout')
  }
}
export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
